//
//  PostTitleCell.m
//  sensen_ios
//
//  Created by mc on 16/3/25.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "PostTitleCell.h"


@implementation PostTitleCell



+(instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString * cellIdentifier = @"PostTitleCell";
    PostTitleCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell ==nil) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
    
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
       [self setupSubViews];
    }
    return self;
}
- (void)setupSubViews{
    // 头像
    self.iconImgView = [[UIImageView alloc] init];
    [self addSubview:_iconImgView];
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self).offset(10);
        make.size.mas_equalTo(CGSizeMake(35, 35));
    }];
   
    _iconImgView.layer.cornerRadius = _iconImgView.frame.size.width / 2;
    _iconImgView.layer.masksToBounds = YES;

    // 昵称
    self.nickLabel = [[UILabel alloc] init];
    _nickLabel.font = B_FONT(15);
    _nickLabel.text = @"发帖人昵称";
    _nickLabel.textColor = rgba(12, 91, 158, 1);
    _nickLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_nickLabel];
    [_nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImgView.mas_right).offset(5);
        make.size.mas_equalTo(CGSizeMake(130, 18));
        make.top.equalTo(self.iconImgView.mas_top).offset(0);
    }];
    
    // 发表时间
    self.createTimeLabel = [[UILabel alloc] init];
    _createTimeLabel.font = FONT(13);
   
    _createTimeLabel.textColor = [UIColor lightGrayColor];
    _createTimeLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:_createTimeLabel];
    [_createTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nickLabel.mas_left).offset(0);
        make.size.mas_equalTo(CGSizeMake(130, 15));
        make.bottom.equalTo(self.iconImgView.mas_bottom).offset(0);
    }];
    
}

- (void)setPostModel:(PostModel *)postModel{
    _postModel = postModel;
    _nickLabel.text = postModel.author;
    if (_postModel.nickname == nil || _postModel.nickname.length == 0) {
        _nickLabel.text = _postModel.author;
    }else{
        _nickLabel.text = _postModel.nickname;
    }

    
    [_iconImgView setImageURLStr:postModel.authorImage placeholder:DEFAULT_IMAGE];
    // 设置头像圆角
    _iconImgView.layer.cornerRadius = 15;
    _iconImgView.layer.masksToBounds = YES;
    //_iconImgView.image = [UIImage imageNamed:@"person_message_disabled"];
    _createTimeLabel.text = postModel.dateline_show;
}

- (void)setPostReplyModel:(PostReplyModel *)postReplyModel{
    _postReplyModel = postReplyModel;
    if (_postReplyModel.nickname == nil || _postReplyModel.nickname.length == 0) {
        _nickLabel.text = postReplyModel.post_author;
    }else{
        _nickLabel.text = _postReplyModel.nickname;
    }
    _iconImgView.image = [UIImage imageNamed:@"person_message_disabled"];
    _createTimeLabel.text = postReplyModel.post_dateline_show;
    [_iconImgView setImageURLStr:postReplyModel.authorImage placeholder:DEFAULT_IMAGE];
    // 设置头像圆角
    _iconImgView.layer.cornerRadius = 15;
    _iconImgView.layer.masksToBounds = YES;
}


@end
